package com.zh.note;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

/**
 * @Author: zhanghuan
 * @date: 2023/4/2 10:44
 * @description: create it
 * @ImportResource导入Spring配置文件 比如，公司使用bean.xml文件生成配置bean，然而你为了省事，想继续复用bean.xml，
 */
@ImportResource("classpath:beans.xml")
@SpringBootApplication
public class GuideApplication {

    public static void main(String[] args) {
        // 返回ioc容器
        ConfigurableApplicationContext run = SpringApplication.run(GuideApplication.class, args);
        // 查看容器里面组件
        // String[] names = run.getBeanDefinitionNames();
        // for (String name : names) {
        //     System.out.println(name);
        // }
//        // 从容器中获取组件
//        User tom = run.getBean("tom", User.class);
//        MyConfig bean = run.getBean(MyConfig.class);
//
//
//        // 通过类型获取组件名称
        String[] beanNamesForType = run.getBeanNamesForType(InterceptorRegistry.class);
        System.out.println(beanNamesForType.length);

//        boolean haha = run.containsBean("haha");
//        System.out.println("haha:  " + haha);
//
//        boolean hehe = run.containsBean("hehe");
//        System.out.println("hehe:  " + haha);


    }
}
